import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 快速排序
 */
public class QuickSort {

    public static void main(String[] args) {
/*        int[] arr = {6,1,2,7,9,3,4,5,10,8};
        quickSort(arr,0,arr.length-1);
        for (int i : arr) {
            System.out.print(i+" ");
        }*/

        int[] arr = new int[8000000];
        for (int i = 0; i < 8000000; i++) {
            arr[i] = (int) (Math.random() * 8000000); //生成一个[0, 8000000) 数
        }

        Date date1 = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        String date1Str = simpleDateFormat.format(date1);
        System.out.println("插入排序前的时间是=" + date1Str);

        //测试插入排序
        quickSort(arr,0,arr.length-1);

        Date date2 = new Date();
        String date2Str = simpleDateFormat.format(date2);
        System.out.println("插入排序后的时间是=" + date2Str);
    }

    public static  void quickSort(int[] arr,int start,int end){
        if (start<end){
            int standard = arr[start];
            int low = start;
            int high = end;
            while (low<high){
                while (low<high&&arr[high]>=standard){
                    high--;
                }
                arr[low] = arr[high];
                while (low<high&&arr[low]<=standard){
                    low++;
                }
                arr[high] = arr[low];
            }
            arr[low] = standard;
            quickSort(arr,start,low);
            quickSort(arr,low+1,end);
        }
    }
}
